<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>07 距某个日期还有多少天</title>
</head>
<body>
    <h1>07 距某个日期还有多少天</h1>
    <input type="date" id="end">
    <input type="button" value="点我" id="btn">
    <div id="app"></div>
</body>
<script>

    // 获取现在的纪元时间

    // 方法一
    var date = new Date();
    console.log(date.getTime());

    // 方法二
    console.log(Date.now());

    (function() {

        // 找节点
        var end = document.getElementById('end');
        var btn = document.getElementById('btn');
        var app = document.getElementById('app');

        btn.onclick = function() {
            var starttime = Date.now();
            var endtime = Date.parse(end.value);
            var dis = endtime - starttime;

            var day = parseInt(dis/1000/60/60/24);

            app.innerHTML = '相差' + day + '天';
        }

    })();

</script>
</html>